home *** CD-ROM | disk | FTP | other *** search
- /* Commlib - XTCommMisc */
- /* Aztec C compiler 1.06i */
- /* Lightspeed C compiler 2.01 */
-
- /* Copyright © 1985,86,87 by small systems guild. All rights reserved. */
-
- #include <extender.h> /* include Commlib and standard Toolbox headers */
-
- Boolean ValidPointer(P)
- Ptr P;
- {
- if ((P == NULL) || /* pointer is null (zero) */
- ((long)P & 1L) || /* pointer is odd */
- ((long)P > (long)TopMem())) /* points above top of RAM */
- return(FALSE); /* then pointer is definitely bad! */
- else
- return(TRUE); /* else pointer is potentially valid*/
- }
-
- Boolean ValidHandle(H)
- Handle H;
- {
- Ptr P;
-
- if (ValidPointer((Ptr)H)) { /* the handle dereferenced is OK */
- P = (Ptr)((long)(*H) & 0x00FFFFFF); /* mask off the master pointer status bits */
- if (ValidPointer(P)) /* the pointer pointed to is OK */
- return(TRUE); /* then Handle is potentially valid */
- }
- return(FALSE); /* Handle doesn't point to a pointer */
- }
-
- void CommVersion(verStr) /* copies version string to indicated location */
- char *verStr;
- {
- XTpstrcpy(verStr,"\ssg Commlib -- version 3d10 Oct 1987");
- }
-
- OSErr XTCloseFile(reply)
- SFReply *reply;
- {
- int fRefNum,errCode;
-
- if (!ValidPointer((Ptr)reply))
- return(nilHandleErr);
-
- errCode = FSOpen(reply->fName,reply->vRefNum,&fRefNum);
- if ((errCode == opWrErr) || (errCode == noErr)) {
- FSClose(fRefNum);
- return(noErr);
- }
- else
- return(errCode);
- }
-
- void BugAlert(s0,s1,s2,s3)
- char *s0,*s1,*s2,*s3;
- {
- EventRecord event;
- WindowRecord wRec;
- WindowPtr wPtr;
- Rect tempRect;
- char *strPtr[4];
- int bytes,strLen,i;
- char theStr[256];
-
- strPtr[0] = s0;
- strPtr[1] = s1;
- strPtr[2] = s2;
- strPtr[3] = s3;
- bytes = 0;
-
- for (i = 0; i < 4; i++) { /* loop thru each of four strings */
- strLen = (unsigned char)strPtr[i]; /* get the string length */
- if (bytes + strLen > 255) { /* if the strings are to long */
- strPtr[i][0] = (unsigned char)(255 - bytes); /* shorten it temp */
- bytes = 255; /* set bytes to 255 (max strlength) */
- }
- bytes += (unsigned char)strPtr[i][0]; /* increment byte count */
- XTpstrconcat(theStr,strPtr[i]); /* concatenate the two strings */
- strPtr[i][0] = (unsigned char)strLen; /* restore original length */
- }
-
- SetRect(&tempRect,100,100,390,300);
- wPtr = CreateWindow(&wRec,&tempRect,"\PBug Alert",1,TRUE,FALSE,FALSE,FALSE,FALSE);
- TextFont(0); /* set grafport font to system font */
-
- SetRect(&tempRect,20,20,270,140);
- TextBox(&(theStr[1]),(unsigned char)theStr[0],&tempRect,teJustLeft);
-
- TextFont(1); /* set grafport font to application font */
- TextSize(10);
- SetRect(&tempRect,10,174,280,190);
- XTpstrcpy(theStr,"\PPress mouse button, return or enter to continue...");
- TextBox(&(theStr[1]),(unsigned char)theStr[0],&tempRect,teJustCenter);
- FrameRoundRect(&tempRect,16,16);
-
- do {
- SystemTask();
- GetNextEvent(mDownMask | keyDownMask,&event);
- switch (event.what) {
- case mouseDown: /* mouse button pressed */
- KillWindow(wPtr);
- RETURN;
- break;
- case keyDown:
- switch ((int)(event.message & charCodeMask)) {
- case 3: /* enter key pressed */
- case 10: /* return key pressed */
- KillWindow(wPtr);
- RETURN;
- break;
- }
- break;
- }
- } while (TRUE);
- }
-
- Boolean XTpstrcpy(toStr,fromStr)
- char *toStr,*fromStr;
- {
- int i;
-
- if ((toStr == NULL) || (fromStr == NULL))
- return(FALSE);
-
- for (i=0; i <= (unsigned char)(fromStr[0]); i++)
- toStr[i] = fromStr[i];
-
- return(TRUE);
- }
-
- Boolean XTcstrcpy(toStr,fromStr) /* from K & R famous C book, p. 100 */
- char *toStr,*fromStr;
- {
- if ((toStr == NULL) || (fromStr == NULL))
- return(FALSE);
-
- while (*toStr++ = *fromStr++)
- ;
-
- return(TRUE);
- }
-
- Boolean XTctopstr(cStr,pStr)
- char *cStr,*pStr;
- {
- int i;
-
- if (!ValidPointer(cStr) || !ValidPointer(pStr))
- return(FALSE);
-
- for (i = 0;cStr[i] != '\0';i++) {
- pStr[i+1] = cStr[i];
- if (i >= 255) {
- pStr[0] = (unsigned char)255;
- return(FALSE);
- }
- }
- pStr[0] = (unsigned char)(i - 1);
- return(TRUE);
- }
-
- Boolean XTptocstr(pStr,cStr)
- char *pStr,*cStr;
- {
- int i;
-
- if (!ValidPointer(cStr) || !ValidPointer(pStr))
- return(FALSE);
-
- for (i = 0;i < (unsigned char)pStr[0];i++) {
- cStr[i] = cStr[i+1];
- }
- cStr[i+1] = '\0';
- return(TRUE);
- }
-
- Boolean XTpstrconcat(toStr,fromStr)
- char *toStr,*fromStr;
- {
- int oldLen,newLen,i;
-
- if ((toStr == NULL) || (fromStr == NULL))
- return(FALSE);
-
- oldLen = (unsigned char)(toStr[0]);
- newLen = (unsigned char)(fromStr[0]);
- if (oldLen + newLen > 255)
- return(FALSE);
-
- toStr[0] = oldLen + newLen;
- for (i=1; i <= newLen; i++)
- toStr[oldLen+i] = fromStr[i];
-
- return(TRUE);
- }
-